#!/bin/bash

let testNum=10
let l=400
let r=1000
let k=8
let lamda=1
let wt=500
#清空存数据的文件
filePath="resultData/k.txt"
cat /dev/null > $filePath
> $filePath

echo "k=2"
let k=2
for wt in 100 500 1000 1500
do
    let n=0
    let t=0
    let m=0
    for ((i=0;i<$testNum;i++))
    do
        temp=`../../../build/Kmeans $l $r $k $lamda ../${wt}_${wt}_data.txt`
        temp=($temp)
        n=`echo $n ${temp[1]}|awk '{printf("%.6f",$1+$2)}'`
        t=`echo $t ${temp[2]}|awk '{printf("%.6f",$1+$2)}'`
        m=`echo $m ${temp[3]}|awk '{printf("%.6f",$1+$2)}'`
    done
    echo $n $t $m $testNum|awk '{printf("k=2 %.6f %.6f %.6f \n",$1/$4,$2/$4,$3/$4)}' >> $filePath
    # ../../../build/Kmeans $l $r $k $lamda ../${n}_${n}_data.txt >> $filePath
done

echo "k=4"
let k=4
for wt in 100 500 1000 1500
do
    let n=0
    let t=0
    let m=0
    for ((i=0;i<$testNum;i++))
    do
        temp=`../../../build/Kmeans $l $r $k $lamda ../${wt}_${wt}_data.txt`
        temp=($temp)
        n=`echo $n ${temp[1]}|awk '{printf("%.6f",$1+$2)}'`
        t=`echo $t ${temp[2]}|awk '{printf("%.6f",$1+$2)}'`
        m=`echo $m ${temp[3]}|awk '{printf("%.6f",$1+$2)}'`
    done
    echo $n $t $m $testNum|awk '{printf("k=4 %.6f %.6f %.6f \n",$1/$4,$2/$4,$3/$4)}' >> $filePath
    # ../../../build/Kmeans $l $r $k $lamda ../${n}_${n}_data.txt >> $filePath
done

echo "k=6"
let k=6
for wt in 100 500 1000 1500
do
    let n=0
    let t=0
    let m=0
    for ((i=0;i<$testNum;i++))
    do
        temp=`../../../build/Kmeans $l $r $k $lamda ../${wt}_${wt}_data.txt`
        temp=($temp)
        n=`echo $n ${temp[1]}|awk '{printf("%.6f",$1+$2)}'`
        t=`echo $t ${temp[2]}|awk '{printf("%.6f",$1+$2)}'`
        m=`echo $m ${temp[3]}|awk '{printf("%.6f",$1+$2)}'`
    done
    echo $n $t $m $testNum|awk '{printf("k=6 %.6f %.6f %.6f \n",$1/$4,$2/$4,$3/$4)}' >> $filePath
    # ../../../build/Kmeans $l $r $k $lamda ../${n}_${n}_data.txt >> $filePath
done

echo "k=8"
let k=8
for wt in 100 500 1000 1500
do
    let n=0
    let t=0
    let m=0
    for ((i=0;i<$testNum;i++))
    do
        temp=`../../../build/Kmeans $l $r $k $lamda ../${wt}_${wt}_data.txt`
        temp=($temp)
        n=`echo $n ${temp[1]}|awk '{printf("%.6f",$1+$2)}'`
        t=`echo $t ${temp[2]}|awk '{printf("%.6f",$1+$2)}'`
        m=`echo $m ${temp[3]}|awk '{printf("%.6f",$1+$2)}'`
    done
    echo $n $t $m $testNum|awk '{printf("k=8 %.6f %.6f %.6f \n",$1/$4,$2/$4,$3/$4)}' >> $filePath
    # ../../../build/Kmeans $l $r $k $lamda ../${n}_${n}_data.txt >> $filePath
done

echo "k=16"
let k=16
for wt in 100 500 1000 1500
do
    let n=0
    let t=0
    let m=0
    for ((i=0;i<$testNum;i++))
    do
        temp=`../../../build/Kmeans $l $r $k $lamda ../${wt}_${wt}_data.txt`
        temp=($temp)
        n=`echo $n ${temp[1]}|awk '{printf("%.6f",$1+$2)}'`
        t=`echo $t ${temp[2]}|awk '{printf("%.6f",$1+$2)}'`
        m=`echo $m ${temp[3]}|awk '{printf("%.6f",$1+$2)}'`
    done
    echo $n $t $m $testNum|awk '{printf("k=16 %.6f %.6f %.6f \n",$1/$4,$2/$4,$3/$4)}' >> $filePath
    # ../../../build/Kmeans $l $r $k $lamda ../${n}_${n}_data.txt >> $filePath
done